#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<pair<long int, int>> nums;

bool compare1(pair<long int, int> a, pair<long int, int> b)
{
    return a.second < b.second;
}
bool compare2(pair<long int, int> a, pair<long int, int> b)
{
    return a.first < b.first;
}
void find_ij(int &s, int &e, int start)
{
    // 寻找个位数相等的下标
    for (size_t i = start; i < nums.size(); i++)
    {
        if (nums[start].second == nums[i].second)
        {
            continue;
        }
        else
        {
            s = start;
            e = i;
            break;
        }
    }
}
int main()
{
    int n, temp, bits;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        cin >> temp;
        bits = temp % 10;
        nums.push_back(make_pair(temp, bits));
    }
    sort(nums.begin(), nums.end(), compare1); // 按照个位数排序
    int s, e;
    for (size_t i = 0; i < nums.size() - 1; i++)
    {
        if (nums[i].second != nums[i + 1].second)
        { // 如果相邻两个的个位数不相等，就输出
            cout << nums[i].first << " ";
            continue;
        }
        if (nums[i].second == nums[i + 1].second)
        {
            find_ij(s, e, i);
            sort(nums.begin() + s, nums.begin() + e, compare2); // sort排序范围是左闭右开
            cout << nums[i].first << " ";
            continue;
        }
    }
    cout << nums[nums.size() - 1].first;
    return 0;
}
